﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TheVerge.Base.Models
{
    public class VMCategories : VMSection<VMCategory>
    {
        public override string DisplayName { get { return @"Categories"; } }

        protected override void Load(Action<VMCategory[]> results)
        {
            API.GetCategories(result =>
            {
                if (result == null)
                    results(null);
                else
                    results(result.All.OrderBy(c => c.Title).Select(c => new VMCategory(c)).ToArray());
            }, error => results(null));
        }
    }

    public class VMCategory : VMEntries<ArticleEntry>
    {
        private Category BackingCategory;
        public int CategoryId { get { return BackingCategory.Id; } }

        public override string DisplayName { get { return @"Category"; } }

        public VMCategory(Category c)
        {
            BackingCategory = c;
        }

        protected override void LoadMoreImp(Action<APIResponse<ArticleEntry>> OnFinished, Action<Exception> OnError)
        {
            API.GetCategoryEntries(LastPageLoaded + 1, CategoryId, OnFinished, OnError);
        }

        public override string ToString()
        {
            return BackingCategory.Title;
        }
    }

}
